package com.itheima.controller;

import com.itheima.pojo.User;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;

/**
 * Description:
 *
 * @author codermao
 * @date 2023/11/7 18:43
 * <p>
 *  TODO：restful的快速开发
 *
 *      1。@RestController = @Controller + @ResponseBody
 *          1)@Controller：添加当前类到IOC容器中
 *          2）@ResponseBody：返回值会被放到响应体中
 *      2.@RequestMapping 写在类上
 *          1）@GetMapping
 *          2）@PostMapping
 *          3）@PutMapping
 *          4）@DeleteMapping
 */
//@Controller
//@ResponseBody
@RestController
@RequestMapping(value = "/rest", produces = "text/html;charset=utf-8")
public class RestController2 {
    //    @RequestMapping(method = RequestMethod.GET)
    @GetMapping
    public String getAll() {
        return "get：查询";
    }

//    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @GetMapping("/{id}")
    public String getById(@PathVariable Integer id) {
        System.out.println("getById：查询" + id);
        return "getById：根据id查询";
    }

//    @RequestMapping(value = "/{page}/{size}", method = RequestMethod.GET)
    @GetMapping("/{page}/{size}")
    public String getByPage(@PathVariable Integer page, @PathVariable Integer size) {
        System.out.println("getByPage：查询" + page + "," + size);
        return "getByPage：分页查询";
    }

    @PostMapping
    public String post(@RequestBody User user) {
        System.out.println("post：新增" + user);
        return "post：新增";
    }

//    @RequestMapping(method = RequestMethod.PUT)
    @PutMapping
    public String put(@RequestBody User user) {
        System.out.println("put修改：" + user);
        return "put：修改";
    }

//    @RequestMapping(method = RequestMethod.DELETE)
    @DeleteMapping
    public String delete() {
        return "delete：删除";
    }

//    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    @RequestMapping("/{id}")
    public String delete2(@PathVariable Integer id) {
        System.out.println("删除id：" + id);
        return "delete：删除";
    }
}
